[HEADER]	
[/HEADER]	
	
[TEXTURES]
	FILE base 	body.pvr  	LINEAR-LINEAR-LINEAR
[/TEXTURES]	
	
[VERTEXSHADER]	
	NAME VertShader	
	[GLSL_CODE]	
	attribute highp vec3	inVertex;
	attribute highp vec3	inNormal;
	attribute highp vec2	inTexCoord;
	attribute highp vec4	inBoneIndex;
	attribute highp vec4	inBoneWeight;
	
	uniform highp   mat4 	ViewProjMatrix;
	uniform mediump vec3 	LightDirWorld;
	uniform mediump	int		BoneCount;
	uniform highp mat4		boneMatrixArray[8];
	uniform highp mat3 		boneMatrixArrayIT[8];
	
	varying lowp    float LightIntensity;
	varying mediump vec2  TexCoord;

	void main(void)
	{
		mediump ivec4 boneIndex = ivec4(inBoneIndex);
		mediump vec4 boneWeights = inBoneWeight;
		
		if(BoneCount>0)
		{
			highp mat4 boneMatrix = boneMatrixArray[boneIndex.x];
			mediump mat3 normalMatrix = boneMatrixArrayIT[boneIndex.x];

			highp vec4 position = boneMatrix * vec4(inVertex, 1.0) * boneWeights.x;
			mediump vec3 worldNormal = normalMatrix * inNormal * boneWeights.x;
			
			for (lowp int i = 1; i < 3; ++i)
			{
				if(i<BoneCount)
				{
					// "rotate" the vector components
					boneIndex = boneIndex.yzwx;
					boneWeights = boneWeights.yzwx;
				
					boneMatrix = boneMatrixArray[boneIndex.x];
					normalMatrix = boneMatrixArrayIT[boneIndex.x];

					position += boneMatrix * vec4(inVertex, 1.0) * boneWeights.x;
					worldNormal += normalMatrix * inNormal * boneWeights.x;
				}
			}		
			gl_Position = ViewProjMatrix * position;
			// Simple diffuse lighting
			LightIntensity = max(0.0, dot(normalize(worldNormal), -LightDirWorld));
		}	

		TexCoord = inTexCoord.st;
	}	
	[/GLSL_CODE]	
[/VERTEXSHADER]	
	
[FRAGMENTSHADER]	
	NAME FragShader	
	[GLSL_CODE]	
	uniform sampler2D sTexture;
	
	varying lowp    float LightIntensity;
	varying mediump vec2  TexCoord;
	
	void main()
	{
	    gl_FragColor = texture2D(sTexture, TexCoord) * LightIntensity;
	}
	[/GLSL_CODE]	
[/FRAGMENTSHADER]	
 	
[EFFECT] 	
	NAME		Effect	
		
	ATTRIBUTE	inVertex			POSITION	
	ATTRIBUTE	inNormal			NORMAL
	ATTRIBUTE	inTexCoord			UV0
	ATTRIBUTE	inBoneIndex			BONEINDEX
	ATTRIBUTE	inBoneWeight		BONEWEIGHT
	
	UNIFORM 	LightDirWorld		LIGHTDIRWORLD
	UNIFORM		ViewProjMatrix		VIEWPROJECTION
	UNIFORM		BoneCount			BONECOUNT
	UNIFORM		boneMatrixArray		BONEMATRIXARRAY
	UNIFORM		boneMatrixArrayIT	BONEMATRIXARRAYIT
	
	UNIFORM		sTexture			TEXTURE0

	TEXTURE 0 	base
	
	FRAGMENTSHADER 	FragShader	
	VERTEXSHADER	VertShader	
[/EFFECT]	

